package com.yakumosakura.yakumoblade.blade;

import com.yakumosakura.yakumoblade.Yakumoblade;
import com.yakumosakura.yakumoblade.registry.slashblade.YAItem;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.api.registration.ISubtypeRegistration;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.init.SBItems;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

@JeiPlugin
public class JEICompat implements IModPlugin {
    public JEICompat() {
    }



    public ResourceLocation getPluginUid() {
        return SlashBlade.prefix("slashblade");
    }

    public void registerItemSubtypes(ISubtypeRegistration registration) {
        registration.registerSubtypeInterpreter(YAItem.getItem(YAItem.SlashBladeOfYakumoBlade), mods.flammpfeil.slashblade.compat.jei.JEICompat::syncSlashBlade);
    }

    public static String syncSlashBlade(ItemStack stack, UidContext context) {
        stack.getCapability(ItemSlashBlade.BLADESTATE).ifPresent((cap) -> {
            if (stack.getOrCreateTag().contains("bladeState")) {
                cap.deserializeNBT(stack.getOrCreateTag().getCompound("bladeState"));
            }

        });
        return (String)stack.getCapability(ItemSlashBlade.BLADESTATE).map((cap) -> cap.getTranslationKey()).orElse("");
    }
}
